<?php
namespace Common\Model;
use Common\Model\AiModel;
class AdminModel extends AiModel {

	protected $_validate = array(
		array('username','require','请填写账号'),
		array('repassword','password','确认密码不正确',0,'confirm'),
		array('username','','账号已存在',0,'unique',1),		
	);

	protected $_auto = array ( 
		array('password','pwd_md5',3,'function') , 
		array('password','',3,'ignore'),		
		array('last_time','time',3,'function'),
		array('last_ip','get_client_ip',3,'function'),
	);
	
	/**
	 * 登录判断
	 * @param unknown $username		账号
	 * @param unknown $password		密码
	 * @return 登录成功返回账号信息关联数组 否则返回false
	 */
	function login($username, $password) {
		$admin = $this->where("username='{$username}' AND password='".md5($password)."'")->find();
		if ($admin) {
			M('Admin')->where('id='.$admin['id'])->data(array('last_time' => time(),'last_ip' => get_client_ip()))->save();			
		}
		return $admin;
	}	
	
	/**
	 * 医院管理登录判断
	 * @param unknown $username
	 * @param unknown $password
	 * @return mixed|boolean|NULL|string|unknown|object
	 */
    function HpLogin($username, $password) {
		$HpAdmin = M('Hospital')->where("name='{$username}' AND password='".md5($password)."'")->find();
		return $HpAdmin;
	}	
}